//
//  RegisterViewController.m
//  ZYTS-iPhone
//
//  Created by yuzhou on 12-12-13.
//  Copyright (c) 2012年 wzyk. All rights reserved.
//

#import "RegisterViewController.h"

@interface RegisterViewController ()

@end

@implementation RegisterViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [usernameField resignFirstResponder];
    [mailField resignFirstResponder];
    [passwordField resignFirstResponder];
    [confirmField resignFirstResponder];
    return YES;
}

- (IBAction)commitRegister:(id)sender
{
    [self textFieldShouldReturn:nil];
    if (usernameField.text.length && mailField.text.length && passwordField.text.length && confirmField.text.length) {
        if (![passwordField.text isEqualToString:confirmField.text]) {
            ABPromptView *promptView = [[[ABPromptView alloc] initWithTitle:@"请填写用户名或密码"] autorelease];
            [promptView show];
            return;
        }
        [[AuthorManager defaultManager] registerWithUsername:usernameField.text password:passwordField.text email:mailField.text];
    }
    else {
        ABPromptView *promptView = [[[ABPromptView alloc] initWithTitle:@"请完整填写资料"] autorelease];
        [promptView show];
    }
}

- (IBAction)navBack:(id)sender
{
//    UINavigationController *navController = (UINavigationController *)self.view.window.rootViewController;
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [usernameField release];
    [mailField release];
    [passwordField release];
    [confirmField release];
    [super dealloc];
}
- (void)viewDidUnload {
    [usernameField release];
    usernameField = nil;
    [mailField release];
    mailField = nil;
    [passwordField release];
    passwordField = nil;
    [confirmField release];
    confirmField = nil;
    [super viewDidUnload];
}
@end
